package qldc.pm.qlktcsdldc.data;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import javax.portlet.PortletConfig;

import qldc.pm.qlktcsdldc.dto.LichSuDTO;
import qldc.pm.qlktcsdldc.emun.ThongTinThayDoiEnum;
import qldc.pm.qlktcsdldc.service.LichSuCongDanLocalServiceUtil;
import qldc.pm.qlktcsdldc.utils.Utils;
import qldc.pm.qtht.dmdc.utils.DiaChiUtils;

import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.language.LanguageUtil;
import com.liferay.portal.kernel.util.Validator;

public class UtilsData {
	public static List<LichSuDTO> getLichSu(String soDinhDanhCaNhan, long thongTinThayDoiId, Locale locale , PortletConfig portletConfig ) throws SystemException{
		//CongDanDTO congDanDTO = CongDanDTOLocalServiceUtil.findBySoDinhDanhCaNhan(soDinhDanhCaNhan);
		List<Object[]>results = null;
		List<LichSuDTO> lichSuDTOs = null;
		if(ThongTinThayDoiEnum.ANHCHANDUNG.getValue() == thongTinThayDoiId){
			
		}else if(ThongTinThayDoiEnum.HOVATEN.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuHoVaTen(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.NTNSINH.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuNgaySinh(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(Utils.formatDateToStringSQL(((Object[])search)[2].toString()));
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(Utils.formatDateToStringSQL(((Object[])searchNext)[2].toString()));
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.GIOITINH.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuGioiTinh(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					int gioiTinh = Integer.parseInt(((Object[])search)[2].toString());
					lichSuDTO.setGiaTriMoi(gioiTinh == 1 ? LanguageUtil.get(portletConfig, locale, "nam") : LanguageUtil.get(portletConfig, locale, "nu"));
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						gioiTinh = Integer.parseInt(((Object[])searchNext)[2].toString());
						lichSuDTO.setGiaTriCu(gioiTinh == 1 ? LanguageUtil.get(portletConfig, locale, "nam") : LanguageUtil.get(portletConfig, locale, "nu"));
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.NOISINH.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuNoiSinh(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					long tinhId = Long.parseLong(((Object[])search)[2].toString());
					long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
					long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
					String diaChi = ((Object[])search)[5].toString();
					String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
					lichSuDTO.setGiaTriMoi(noiSinh);
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
						quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
						phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
						diaChi = ((Object[])searchNext)[5].toString();
						noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriCu(noiSinh);
					}
					if(Validator.isNotNull(search[6])){
						lichSuDTO.setChuThich(((Object[])search)[6].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.QUEQUAN.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuQueQuan(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					long tinhId = Long.parseLong(((Object[])search)[2].toString());
					long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
					long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
					String diaChi = ((Object[])search)[5].toString();
					String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
					lichSuDTO.setGiaTriMoi(noiSinh);
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
						quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
						phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
						diaChi = ((Object[])searchNext)[5].toString();
						noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriCu(noiSinh);
					}
					if(Validator.isNotNull(search[6])){
						lichSuDTO.setChuThich(((Object[])search)[6].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.DANTOC.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuDanToc(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.TONGIAO.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuTonGiao(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.QUOCTICH.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuQuocTich(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.CMND.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuCMND(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.HOCHIEU.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuHoChieu(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
					}
					if(Validator.isNotNull(search[3])){
						lichSuDTO.setChuThich(((Object[])search)[3].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.THUONGTRU.getValue() == thongTinThayDoiId){
			results = LichSuCongDanLocalServiceUtil.lichSuNoiThuongTru(soDinhDanhCaNhan);
			if(Validator.isNotNull(results) && results.size() > 0){
				lichSuDTOs = new ArrayList<LichSuDTO>();
				for(int i=0; i < results.size(); i++){
					Object[] search = results.get(i);
					LichSuDTO lichSuDTO = new LichSuDTO();
					lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
					/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
					if(Validator.isNotNull(nguoiDung)){
						lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
					} */
					long tinhId = Long.parseLong(((Object[])search)[2].toString());
					long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
					long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
					String diaChi = ((Object[])search)[5].toString();
					String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
					lichSuDTO.setGiaTriMoi(noiSinh);
					if(i + 1 < results.size()){
						Object[] searchNext = results.get(i+1);
						tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
						quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
						phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
						diaChi = ((Object[])searchNext)[5].toString();
						noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriCu(noiSinh);
					}
					if(Validator.isNotNull(search[6])){
						lichSuDTO.setChuThich(((Object[])search)[6].toString());
					}
					lichSuDTOs.add(lichSuDTO);
				}
			}
		}else if(ThongTinThayDoiEnum.NOIOHIENTAI.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuNoiOHienTai(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						/* NguoiDung nguoiDung = NguoiDungLocalServiceUtil.fetchNguoiDung(Long.parseLong(((Object[])search)[1].toString()));
						if(Validator.isNotNull(nguoiDung)){
							lichSuDTO.setCanBoThucHien(nguoiDung.getHoVaTen());
						} */
						long tinhId = Long.parseLong(((Object[])search)[2].toString());
						long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
						long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
						String diaChi = ((Object[])search)[5].toString();
						String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriMoi(noiSinh);
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
							quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
							phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
							diaChi = ((Object[])searchNext)[5].toString();
							noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
							lichSuDTO.setGiaTriCu(noiSinh);
						}
						if(Validator.isNotNull(search[6])){
							lichSuDTO.setChuThich(((Object[])search)[6].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.HOTENCHA.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuHoVaTenCha(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.SDDCHA.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuSoDDCNCha(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.QUOCTICHCHA.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuQuocTichCha(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.HOTENME.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuHoVaTenMe(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.SDDME.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuSoDDCNMe(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.QUOCTICHME.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuQuocTichMe(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.HOTENVOCHONG.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuHoVaTenVoChong(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.SDDVOCHONG.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuSoDDVoChong(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.QUOCTICHVOCHONG.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuQuocTichVoChong(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.HOTENCHUHO.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuHoVaTenChuHo(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.QUANHECHUHO.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuQuanHeChuHo(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.SOSOHOKHAU.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuSoSoHoKhau(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		/*}else if(ThongTinThayDoiEnum.LOAIHO.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuLoaiHo(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}*/
		}else if(ThongTinThayDoiEnum.SOHSHK.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuSoHSHK(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.NGHENGHIEP.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuNgheNghiep(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.NOILAMVIEC.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuNoiLamViec(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						long tinhId = Long.parseLong(((Object[])search)[2].toString());
						long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
						long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
						String diaChi = ((Object[])search)[5].toString();
						String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriMoi(noiSinh);
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
							quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
							phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
							diaChi = ((Object[])searchNext)[5].toString();
							noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
							lichSuDTO.setGiaTriCu(noiSinh);
						}
						if(Validator.isNotNull(search[6])){
							lichSuDTO.setChuThich(((Object[])search)[6].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.ODAUDEN.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuODauDen(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						long tinhId = Long.parseLong(((Object[])search)[2].toString());
						long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
						long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
						String diaChi = ((Object[])search)[5].toString();
						String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriMoi(noiSinh);
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
							quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
							phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
							diaChi = ((Object[])searchNext)[5].toString();
							noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
							lichSuDTO.setGiaTriCu(noiSinh);
						}
						if(Validator.isNotNull(search[6])){
							lichSuDTO.setChuThich(((Object[])search)[6].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.NGAYDEN.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuNgayDen(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(Utils.formatDateToStringSQL(((Object[])search)[2].toString()));
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(Utils.formatDateToStringSQL(((Object[])searchNext)[2].toString()));
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.LYDODEN.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuLyDoDen(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.CHUYENDIDAU.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuChuyenDiDau(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						long tinhId = Long.parseLong(((Object[])search)[2].toString());
						long quanHuyenId = Long.parseLong(((Object[])search)[3].toString());
						long phuongXaId = Long.parseLong(((Object[])search)[4].toString());
						String diaChi = ((Object[])search)[5].toString();
						String noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
						lichSuDTO.setGiaTriMoi(noiSinh);
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							tinhId = Long.parseLong(((Object[])searchNext)[2].toString());
							quanHuyenId = Long.parseLong(((Object[])searchNext)[3].toString());
							phuongXaId = Long.parseLong(((Object[])searchNext)[4].toString());
							diaChi = ((Object[])searchNext)[5].toString();
							noiSinh = DiaChiUtils.createBlockDiaChi(tinhId, quanHuyenId, phuongXaId, diaChi);
							lichSuDTO.setGiaTriCu(noiSinh);
						}
						if(Validator.isNotNull(search[6])){
							lichSuDTO.setChuThich(((Object[])search)[6].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.NGAYCHUYEN.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuNgayChuyen(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(Utils.formatDateToStringSQL(((Object[])search)[2].toString()));
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(Utils.formatDateToStringSQL(((Object[])searchNext)[2].toString()));
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}else if(ThongTinThayDoiEnum.LYDOCHUYEN.getValue() == thongTinThayDoiId){
			
				results = LichSuCongDanLocalServiceUtil.lichSuLyChuyenDi(soDinhDanhCaNhan);
				if(Validator.isNotNull(results) && results.size() > 0){
					lichSuDTOs = new ArrayList<LichSuDTO>();
					for(int i=0; i < results.size(); i++){
						Object[] search = results.get(i);
						LichSuDTO lichSuDTO = new LichSuDTO();
						lichSuDTO.setNgayThayDoi(Utils.formatDateToStringSQL(((Object[])search)[0].toString()));
						lichSuDTO.setGiaTriMoi(((Object[])search)[2].toString());
						if(i + 1 < results.size()){
							Object[] searchNext = results.get(i+1);
							lichSuDTO.setGiaTriCu(((Object[])searchNext)[2].toString());
						}
						if(Validator.isNotNull(search[3])){
							lichSuDTO.setChuThich(((Object[])search)[3].toString());
						}
						lichSuDTOs.add(lichSuDTO);
					}
				}
			
		}
		return lichSuDTOs;
	}
	
}
